# Python 2.6.4
# Project Euler, Problem 62
# Copyright 2010 Talha Zaman

cubes = dict()
i = 1
digits = 1
target = 5
found = False
while not found:
    cube = "".join(sorted(str(i**3)))
    if len(cube) > digits:
        for key in cubes:
            if len(cubes[key])==target:
                print cubes[key], cubes[key][0]**3
                found = True
        digits = len(cube)
        cubes = dict()
    if cube not in cubes: cubes[cube] = [i]
    else: cubes[cube].append(i)
    i += 1
